package chapter3_array;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by yuh on 2018/4/9.
 */
public class TwoSum {

    static void twoSum(int[] nums, int target) {
        int index1 = -1;
        int index2 = -1;
        Map<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < nums.length; i++) {
            map.put(nums[i], i);
        }
        for (int i = 0; i < nums.length; i++) {
            if (map.get(target - nums[i]) != null) {
                index1 = i;
                index2 = map.get(target - nums[i]);
                break;
            }
        }

        System.out.println(index1 + "," + index2);
    }

    public static void main(String[] args) {
        int[] arr = {1,2,3,4,5,6};
        twoSum(arr,7);
    }
}
